<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="操作员" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入操作员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="停车场名称" prop="parkName">
        <el-input
          v-model="queryParams.parkName"
          placeholder="请输入停车场名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号码" prop="carLicenseNumber">
        <el-input
          v-model="queryParams.carLicenseNumber"
          placeholder="请输入车牌号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车主姓名" prop="carName">
        <el-input
          v-model="queryParams.carName"
          placeholder="请输入车主姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆类型" prop="carType">
        <el-select v-model="queryParams.carType" placeholder="请选择车辆类型" clearable size="small">
          <el-option
            v-for="dict in carTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="车主电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入车主电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作时间" prop="createtime">
        <el-date-picker
          clearable size="small"
          v-model="queryParams.createtime"
          type="datetime"
          :picker-options="pickerOptions"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择开始时间">
        </el-date-picker>&ensp;-&ensp;
        <el-date-picker
          clearable size="small"
          v-model="queryParams.endCreatetime"
          type="datetime"
          :picker-options="pickerOptions"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:parkingCarLog:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:parkingCarLog:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="parkingCarLogList" border size="mini" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
      <el-table-column label="操作员" align="center" prop="username" />
      <el-table-column label="车牌号码" align="center" prop="carLicenseNumber" width="110"/>
      <el-table-column label="车主姓名" align="center" prop="carName" />
      <el-table-column label="车主电话" align="center" prop="phone" width="110"/>
      <el-table-column label="起始时间" align="center" prop="startTime" width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="截至日期" align="center" prop="endTime" width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="余额" align="center" prop="balance" />
      <el-table-column label="操作金额" align="center" prop="operationMoney" >
        <template slot-scope="scope">
          <span>{{scope.row.operationMoney / 100 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作时间" align="center" prop="createtime" width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="描述" align="center" prop="description" width="150"/>
      <el-table-column label="操作内容" align="center" prop="content" width="135">
        <template slot-scope="scope">
          <el-popover
            placement="top-start"
            width="300"
            trigger="hover"
            :disabled="scope.row.content.length <= 8"
          >
            <div>{{ scope.row.content }}</div>
            <span slot="reference" v-if="scope.row.content.length <= 10">{{scope.row.content}}</span>
            <span slot="reference" v-if="scope.row.content.length > 10">{{scope.row.content.substr(0, 8) + "..."}}</span>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="停车场编号" align="center" prop="parkCode" width="110"/>
      <el-table-column label="停车场名称" align="center" prop="parkName" width="120"/>
      <el-table-column label="模块" align="center" prop="module" />
      <el-table-column label="小区名称" align="center" prop="communityName" />
      <el-table-column label="车辆类型" align="center" prop="carType" :formatter="carTypeFormat" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listParkingCarLog, getParkingCarLog, delParkingCarLog, addParkingCarLog, updateParkingCarLog, exportParkingCarLog } from "@/api/system/parkingCarLog";
import Editor from '@/components/Editor';

export default {
  name: "ParkingCarLog",
  components: {
    Editor,
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆日志记录表格数据
      parkingCarLogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      pickerOptions: {
        disabledDate(time){
          return time.getTime() > Date.now()
        }
      },
      // 车辆类型(1 临时车，2 固定车)字典
      carTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: undefined,
        parkName: undefined,
        carLicenseNumber: undefined,
        carName: undefined,
        carType: undefined,
        phone: undefined,
        createtime: undefined,
        endCreatetime: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("car_log_type").then(response => {
      this.carTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询车辆日志记录列表 */
    getList() {
      this.loading = true;
      listParkingCarLog(this.queryParams).then(response => {
        this.parkingCarLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 车辆类型(1 临时车，2 固定车)字典翻译
    carTypeFormat(row, column) {
      return this.selectDictLabel(this.carTypeOptions, row.carType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        username: undefined,
        parkName: undefined,
        carLicenseNumber: undefined,
        carName: undefined,
        carType: undefined,
        phone: undefined,
        createtime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.compareTime(this.queryParams.createtime,this.queryParams.endCreatetime) == false){
        this.msgError("请选择正确的时间段");
        return false;
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除车辆日志记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delParkingCarLog(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有车辆日志记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportParkingCarLog(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
